/**
 * Copyright (C) 2021 - 2031 O-Cubes Co., Ltd.
 */

/****************************************************************
 *  @file    sfud_flash_def.h
 *  @brief   Flash types and spec Macro definition Header File of SFUD
 *  @version v1.0
 *  @date    03. Apr. 2023
 *  @author  gonght
 ****************************************************************/
#ifndef __SFUD_FLASH_DEF_H__
#define __SFUD_FLASH_DEF_H__

#include <stdint.h>
#include "sfud_cfg.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
 * flash program(write) data mode
 */
enum sfud_write_mode {
	SFUD_WM_PAGE_256B = 1 << 0,                            /**< write 1 to 256 bytes per page */
	SFUD_WM_BYTE = 1 << 1,                                 /**< byte write */
	SFUD_WM_AAI = 1 << 2,                                  /**< auto address increment */
	SFUD_WM_DUAL_BUFFER = 1 << 3,                          /**< dual-buffer write, like AT45DB series */
};

/* manufacturer information */
typedef struct {
	const char *name;
	uint8_t id;
} sfud_mf;

/* flash chip information */
typedef struct {
	const char *name;                            /**< flash chip name */
	uint8_t mf_id;                               /**< manufacturer ID */
	uint8_t type_id;                             /**< memory type ID */
	uint8_t capacity_id;                         /**< capacity ID */
	uint32_t capacity;                           /**< flash capacity (bytes) */
	uint16_t write_mode;                         /**< write mode @see sfud_write_mode */
	uint32_t erase_gran;                         /**< erase granularity (bytes) */
	uint8_t erase_gran_cmd;                      /**< erase granularity size block command */
} sfud_flash_chip;

/* QSPI flash chip's extended information compared with SPI flash */
typedef struct {
	uint8_t mf_id;                               /**< manufacturer ID */
	uint8_t type_id;                             /**< memory type ID */
	uint8_t capacity_id;                         /**< capacity ID */
	uint8_t read_mode;                           /**< supported read mode on this qspi flash chip */
} sfud_qspi_flash_ext_info;

/** Definitions for GD25Q40C*/
#define SFUD_DFT_DUMMY_CYCLES                          8
#define SFUD_QUAD_IO_DUMMY_CYCLES                      4

#define SFUD_STD_INS_LINE                              1

#define SFUD_STD_ADDR_LINE                             1
#define SFUD_DUAL_OUT_ADDR_LINE                        SFUD_STD_ADDR_LINE
#define SFUD_DUAL_IO_ADDR_LINE                         2
#define SFUD_QUAD_OUT_ADDR_LINE                        SFUD_STD_ADDR_LINE
#define SFUD_QUAD_IO_ADDR_LINE                         4

#define SFUD_STD_DATA_LINE                             1
#define SFUD_DUAL_DATA_LINE                            2
#define SFUD_QUAD_DATA_LINE                            4

/* SFUD support manufacturer JEDEC ID */
#define SFUD_MF_ID_GIGADEVICE                          0xC8
#define SFUD_MF_ID_GIANTEC                             0xC4

/* SFUD supported manufacturer information table */
#define SFUD_MF_TABLE                                         \
{                                                             \
	{"GigaDevice", SFUD_MF_ID_GIGADEVICE},                \
	{"GIANTEC",    SFUD_MF_ID_GIANTEC},                   \
}

/* SFUD supported flash chip information table. If the flash not support JEDEC JESD216 standard,
 * then the SFUD will find the flash chip information by this table. You can add other flash to here then
 *  notice me for update it. The configuration information name and index reference the sfud_flash_chip structure.
 * | name | mf_id | type_id | capacity_id | capacity | write_mode | erase_gran | erase_gran_cmd |
 */
#define SFUD_FLASH_CHIP_TABLE                                                                                           \
{                                                                                                                       \
	{"GD25Q40E", SFUD_MF_ID_GIGADEVICE, 0x40, 0x13, 512L*1024L, SFUD_WM_PAGE_256B, 4L*1024L, 0x20},                 \
	{"GT25Q40C", SFUD_MF_ID_GIANTEC, 0x40, 0x13, 512L*1024L, SFUD_WM_PAGE_256B, 4L*1024L, 0x20},                    \
}

#ifdef __cplusplus
}
#endif

#endif /* __SFUD_FLASH_DEF_H__ */
